package com.ylcy.ads.launch;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.widget.Toast;

/**
 * 适配多应用
 */
public class LaunchApp {
    /**
     * 启动应用
     * @param context
     * @param pkgName
     */
    public static void launch(Context context, String pkgName) {
        PackageManager packageManager = context.getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage(pkgName);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    /**
     * 检测应用是否安装
     * @param context
     * @param pkgName
     */
    public static boolean check(Context context, String pkgName){
        PackageManager packageManager = context.getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage(pkgName);
        if (intent == null){
            Toast.makeText(context, "检查到您手机没有安装选择的应用，请安装后使用该功能", Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }

}
